package com.jiangjiang.eshop.auth.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.auth.dao.AccountRoleRelationshipMapper;
import com.jiangjiang.eshop.auth.domain.AccountPriorityRelationshipEntity;
import com.jiangjiang.eshop.auth.domain.AccountRoleRelationshipEntity;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Jianghaowen
 * @Date 2021/6/18
 * @Description: 账户和角色关联关系service
 * @Version V1.0
 **/
@Service
public class AccountRoleRelationshipService extends ServiceImpl<AccountRoleRelationshipMapper, AccountRoleRelationshipEntity> {
    /**
     * 根据角色id,查询关联的账户数
     *
     * @param roleId 角色id
     * @return 查询结果
     */
    public List<AccountRoleRelationshipEntity> queryRelationByRoleId(Long roleId) {
        return this.list(Wrappers.<AccountRoleRelationshipEntity>lambdaQuery()
                .eq(AccountRoleRelationshipEntity::getRoleId, roleId));
    }

    /**
     * 根据用户账户id查询账户和角色关联关系
     *
     * @param accountId 账户id
     * @return 查询结果
     */
    public List<AccountRoleRelationshipEntity> queryRoleRelationsByAccountId(Long accountId) {
        LambdaQueryWrapper<AccountRoleRelationshipEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(AccountRoleRelationshipEntity::getAccountId, accountId);
        return this.list(wrapper);
    }
}
